<script type="text/javascript">
$(document).ready(function(){
$("#propinsi_id").change(function(){
var val = $(this).val();

$.ajax({
                    type: "POST",
                    url: "<?php echo Yii::app()->createUrl('/MstPropinsi/getKota'); ?>",
                    data: "kd_propinsi="+val,
                    success: function(data){
                        
                        $("#kota_id").html(data);
                        
                    }
     });


});
});
</script>

<div class="form">

    <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id'=>'mst-perusahaan-asuransi-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

    <p class="help-block">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>
	<div class="row">
					<!--=== Validation Example 1 ===-->
					<div class="col-md-6">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> Form Perusahaan Asuransi</h4>
							</div>
							<div class="widget-content">
			<?php //echo $form->dropDownListControlGroup($model,'jenis_asuransi_id',CHtml::listData(MstJnsAsuransi::model()->findAll(),'id','name'), array('prompt'=>'choose one','class'=>'form-control')); ?>

			<?php 
			$lastNumber = MstPerusahaanAsuransi::model()->find()->id;
			$number = (int)$lastNumber+1;
			$value = 'INS'.$number;
	        ?>

            <?php echo $form->textFieldControlGroup($model,'no_insurance',array('class'=>'form-control','maxlength'=>50, 'readonly'=>'readonly', 'value'=>$value)); ?>

            <?php echo $form->textFieldControlGroup($model,'name',array('class'=>'form-control','maxlength'=>50)); ?>

            <?php echo $form->textAreaControlGroup($model,'address',array('class'=>'form-control','maxlength'=>50)); ?>

            <?php echo $form->dropDownListControlGroup($model,'province_id',CHtml::listData(MstPropinsi::model()->findAll(array('order'=>'id')), 'id', 'nm_propinsi'),
            	array('class'=>'form-control', 'prompt'=>'Pilih Propinsi',
            		'value'=>'0',
					'id'=>'propinsi_id')); ?>
			</div>
			</div>
			</div>
			<!--=== Validation Example 1 ===-->
					<div class="col-md-6">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> Company Form</h4>
							</div>
							<div class="widget-content">

			<?php
			if($model->isNewRecord){
			?>	
			
			<?php echo $form->dropDownListControlGroup($model,'city_id',CHtml::listData(MstCity::model()->findAll('id_propinsi=0'), 'id', 'nm_city'),array('class'=>'form-control', 'prompt'=>'Pilih Kota','id'=>'kota_id')); ?>
			
			<?php
			}else{
			?>
						
			<?php echo $form->dropDownListControlGroup($model,'city_id',CHtml::listData(MstCity::model()->findAll('id_propinsi='.$model->province_id), 'id', 'nm_city'),array('class'=>'form-control', 
			'prompt'=>'Pilih Kota',
			'id'=>'kota_id',
			'options' => array($model->city_id=>array('selected'=>true)),
			)); ?>

			<?php
			}
			?>

            <?php echo $form->textFieldControlGroup($model,'zip_code',array('class'=>'form-control','maxlength'=>10)); ?>

            <?php echo $form->textFieldControlGroup($model,'phone',array('class'=>'form-control','maxlength'=>20)); ?>

            <?php echo $form->textFieldControlGroup($model,'fax',array('class'=>'form-control','maxlength'=>20)); ?>
		</div>
		</div>
		</div>
		</div>
		
		<div class="row">

				<?php
				if($model->isNewRecord){
					for($i=1;$i<=3;$i++){
				?>

				<div class="col-md-4">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> Bank Account <?php echo $i ?></h4>
							</div>
							<div class="widget-content">
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Nomor Rekening:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="text" name="account_number[]">
									</div>
								</div>
								
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Nama Rekening:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="text" name="account_name[]">
									</div>
								</div>
								
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Nama Bank:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="text" name="bank_name[]">
									</div>
								</div>
								
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Cabang:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="text" name="branch[]">
									</div>
								</div>
									
								<div class="control-group">
										<label class="control-label" for="MstClient_city_id">Jenis Mata Uang:</label>
										<div class="controls">
											<select class="form-control" id="currency" name="currency[]">
											<?php $curs = MstCurrency::model()->findAll();
											foreach($curs as $cur):
											?>
												<option value="<?php echo $cur->id; ?>"><?php echo $cur->name; ?></option>
											<?php endforeach; ?>
											</select>
										</div>
								</div>
									
							</div>
						</div>
					</div>
					<!-- /Validation Example 2 -->

				<?php
				}
				}

				else{
					$perusahaanAsuransiAccount = MstPerusahaanAsuransiAccount::model()->findAll('mst_perusahaan_id='.$model->id.' order by id');
					$j = 1;
					foreach($perusahaanAsuransiAccount as $row){
				?>
				
				<div class="col-md-4">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> Bank Account <?php echo $j ?></h4>
							</div>
							<div class="widget-content">
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Nomor Rekening:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="hidden" name="id_account[]" value="<?php echo $row->id; ?>">
										<input id="MstClient_city_id" class="form-control" type="text" name="account_number[]" value="<?php echo $row->account_number; ?>">
									</div>
								</div>
								
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Nama Rekening:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="text" name="account_name[]" value="<?php echo $row->account_name; ?>">
									</div>
								</div>
								
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Nama Bank:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="text" name="bank_name[]" value="<?php echo $row->bank_name; ?>">
									</div>
								</div>
								
								<div class="control-group">
									<label class="control-label" for="MstClient_city_id">Cabang:</label>
									<div class="controls">
										<input id="MstClient_city_id" class="form-control" type="text" name="branch[]" value="<?php echo $row->branch; ?>">
									</div>
								</div>
									
								<div class="control-group">
										<label class="control-label" for="MstClient_city_id">Jenis Mata Uang:</label>
										<div class="controls">
											<select class="form-control" id="currency" name="currency[]">
											<?php $curs = MstCurrency::model()->findAll();
											foreach($curs as $cur):
											?>

											<?php
											if($cur->id == $row->currency_id){
											?>
											<option selected="selected" value="<?php echo $cur->id; ?>"><?php echo $cur->name; ?></option>

											<?php
											}else{
											?>
											<option value="<?php echo $cur->id; ?>"><?php echo $cur->name; ?></option>
											<?php
											}
											?>

											<?php endforeach; ?>
											</select>
										</div>
								</div>
									
							</div>
						</div>
					</div>
					<!-- /Validation Example 2 -->

				<?php
				$j = $j+1;
				}
				}
				?>

				
					
	</div>

            

        <div class="form-actions">
        <?php echo TbHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
		    'color'=>TbHtml::BUTTON_COLOR_PRIMARY,
		    'size'=>TbHtml::BUTTON_SIZE_LARGE,
		)); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->